# Maintainer: Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Juergen Hoetzel <juergen@hoetzel.info>
# Contributor: basilburn (basilburn), Paul Bredbury (brebs)
# Contributor: lolilolicon

pkgname=privoxy
pkgver=3.0.34
pkgrel=1
pkgdesc='A web proxy with advanced filtering capabilities.'
arch=('loong64' 'x86_64')
url='https://www.privoxy.org'
license=('GPL2')
depends=('pcre' 'zlib')
backup=('etc/privoxy/'{config,trust,match-all.action,{default,user}.{action,filter}}
        'etc/logrotate.d/privoxy')
source=("https://downloads.sourceforge.net/ijbswa/${pkgname}-${pkgver}-stable-src.tar.gz"
        'privoxy.logrotate.d'
        'privoxy.sysusers'
        'privoxy.service')
sha256sums=('e6ccbca1656f4e616b4657f8514e33a70f6697e9d7294356577839322a3c5d2c'
            '769740ea3c15228f24b559192e7b3f45b95dcf9040e2b25f15bfdfae8af86ce3'
            '6681231552f431962dda2ac49187df833b2b57544eac97ca94d1f4207b27b04c'
            '30237681b6b117ce0d21efb3eeb896202744a32f9740fede1011b5dc84ff9f23')

build() {
  cd "${srcdir}/${pkgname}-${pkgver}-stable"

  autoheader
  autoconf
  ./configure --prefix=/usr --sysconfdir=/etc/privoxy --enable-compression

  make
  sed -i '
    s+^confdir \.+confdir /etc/privoxy+
    s+^logdir \.+logdir /var/log/privoxy+
    s+^#\?user-manual .*+user-manual /usr/share/doc/privoxy/user-manual/+' config
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}-stable"

  install -Dm644 "$srcdir/privoxy.service" "$pkgdir/usr/lib/systemd/system/privoxy.service"
  install -Dm644 "$srcdir/privoxy.sysusers" "$pkgdir/usr/lib/sysusers.d/privoxy.conf"
  install -Dm644 "$srcdir/privoxy.logrotate.d" "$pkgdir/etc/logrotate.d/privoxy"

  install -Dm755 {,"$pkgdir"/usr/bin/}privoxy
  install -Dm644 {,"$pkgdir"/usr/share/man/man8/}privoxy.8
  install -d -o42 -g42 "$pkgdir"/var/log/privoxy

  install -d "$pkgdir"/etc/privoxy/
  install -m644 config trust *.{action,filter} "$pkgdir"/etc/privoxy/ # -m0660 upstream
  find templates -type f -exec install -Dm644 '{}' "$pkgdir"/etc/privoxy/'{}' \;

  (d="$pkgdir"/usr/share/doc/privoxy
  cd doc/webserver
  install -Dm644 {privoxy-,"$d"/}index.html
  install -m644 p_doc.css ../../{AUTHORS,README,ChangeLog} "$d"/
  install -Dm644 {,"$d"/user-manual/}p_doc.css
  find user-manual developer-manual faq man-page \( -name '*.html' -o -name '*.jpg' \) \
    -exec install -Dm644 '{}' "$d"/'{}' \;)
}
